//
//  MusicSegTableViewCell.m
//  Movie
//
//  Created by cjy on 16/3/25.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "MusicSegTableViewCell.h"
#import "ModelTrailer.h"
#import <UIImageView+WebCache.h>
@implementation MusicSegTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imageHead = [[UIImageView alloc]init];
        [self.contentView addSubview:self.imageHead];
        
        self.label = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.label];
        
        self.ueseName = [[UILabel alloc]init];
        [self.contentView addSubview:self.ueseName];
        
    }
    
    return self;
}

- (void)layoutSubviews{

    [super layoutSubviews];
    
    self.imageHead.frame = CGRectMake(15.f, 15.f, 30.f, 30.f);
    self.imageHead.layer.masksToBounds = YES;
    self.imageHead.layer.cornerRadius = 15;

//    
//    self.label.frame = CGRectMake(80, 50, self.contentView.frame.size.width, 10);
    self.label.textColor = [UIColor lightGrayColor];

    self.ueseName.frame = CGRectMake(80, 20, self.contentView.frame.size.width, 10);
    self.ueseName.font = [UIFont systemFontOfSize:13];
    self.ueseName.textColor = [UIColor whiteColor];
}

- (void)passSeg:(ModelTrailer *)model{
    self.label.text = model.content;

    self.label.frame = CGRectMake(10, 50 , [UIScreen mainScreen].bounds.size.width-20, [[self class] heightForLabel:self.label.text]);
    self.label.numberOfLines = 0;
    self.label.font = [UIFont systemFontOfSize:14];
    self.ueseName.text = model.userName;
    [self.imageHead sd_setImageWithURL:[NSURL URLWithString:model.userHeadImg] placeholderImage:[UIImage imageNamed:@"zwt"]];
}


+ (CGFloat)heightForLabel:(NSString *)text{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, 0) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil];
    
    return rect.size.height ;
}


+ (CGFloat)heightForCell:(ModelTrailer *)model{
    
    CGFloat height =  [MusicSegTableViewCell heightForLabel:model.content];
    
    return height + 80;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
